<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="教职工号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherFacultyCode">
              <a-input v-model="model.teacherFacultyCode" placeholder="请输入教职工号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherName">
              <a-input v-model="model.teacherName" placeholder="请输入姓名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="电话号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherTel">
              <a-input v-model="model.teacherTel" placeholder="请输入电话号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="昵称(简称)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherNickname">
              <a-input v-model="model.teacherNickname" placeholder="请输入昵称(简称)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="名字拼音" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teachernamePinyin">
              <a-input v-model="model.teachernamePinyin" placeholder="请输入名字拼音"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="显示顺序" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherOrder">
              <a-input-number v-model="model.teacherOrder" placeholder="请输入显示顺序"  ></a-input-number>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="出生日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherBirth">
              <j-date placeholder="请选择出生日期" v-model="model.teacherBirth"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherGender">
              <a-select v-model="model.teacherGender" placeholder="请选择性别"
                        :getPopupContainer="(target) => target.parentNode">
                <a-select-option :value="1">男</a-select-option>
                <a-select-option :value="2">女</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="身份证号码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherIdNumber">
              <a-input v-model="model.teacherIdNumber" placeholder="请输入身份证号码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="邮箱地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherEmail">
              <a-input v-model="model.teacherEmail" placeholder="请输入邮箱地址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="微信号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherWechatId">
              <a-input v-model="model.teacherWechatId" placeholder="请输入微信号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="QQ" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherQqId">
              <a-input v-model="model.teacherQqId" placeholder="请输入QQ"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="户籍" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherRegistered">
              <a-input v-model="model.teacherRegistered" placeholder="请输入户籍"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="家庭住址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherAddress">
              <a-input v-model="model.teacherAddress" placeholder="请输入家庭住址"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="描述" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherIntroduce">
              <a-input v-model="model.teacherIntroduce" placeholder="请输入描述"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="职称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherTitle">
              <a-input v-model="model.teacherTitle" placeholder="请输入职称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毕业院校" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherUniversity">
              <a-input v-model="model.teacherUniversity" placeholder="请输入毕业院校"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最高学历" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherDegree">
              <a-input v-model="model.teacherDegree" placeholder="请输入最高学历"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="教师资格证编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherCertificateCode">
              <a-input v-model="model.teacherCertificateCode" placeholder="请输入教师资格证编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="银行卡号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherBankId">
              <a-input v-model="model.teacherBankId" placeholder="请输入银行卡号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherStatus">
              <a-input-number v-model="model.teacherStatus" placeholder="请输入状态" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherTtype">
              <a-input-number v-model="model.teacherTtype" placeholder="请输入类型" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="是否启用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherIzOpen">
              <a-input-number v-model="model.teacherIzOpen" placeholder="请输入是否启用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="是否删除" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherIzDelete">-->
<!--              <a-input-number v-model="model.teacherIzDelete" placeholder="请输入是否删除：0：未删除；1：删除" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="学校编码（租户id）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tenantId">-->
<!--              <a-input v-model="model.tenantId" placeholder="请输入学校编码（租户id）"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="民族" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="teacherNation">
              <a-input-number v-model="model.teacherNation" placeholder="请输入民族" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TeaTeacherForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/teacher/teaTeacher/add",
          edit: "/teacher/teaTeacher/edit",
          queryById: "/teacher/teaTeacher/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        if (localStorage.length > 0) {
          let localData = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
          let tenantId = localData.value.tenantId
          this.model.tenantId = tenantId
        }
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>